package com.autonavi.yunda.yunji.core.service.thirdpartyservice.vo;

import com.autonavi.yunda.yunji.common.utils.JsonUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Objects;

@EqualsAndHashCode(callSuper = true)
@Data
public class BaseHttpResponse<T> extends HashMap<String, Object> implements Serializable {
    private boolean success;
    private int code;
    private String msg;
    private T data;

    public T getData(TypeReference<T> typeReference) {
        Object data = get("data");
        if (Objects.isNull(data)) {
            return null;
        }
        String s = JsonUtils.toString(data);
        return JsonUtils.from(s, typeReference);
    }

    public boolean isSuccess() {
        return this.success;
    }
}
